<template>
	<view class="main">
		<view class="top box box-pack-start box-align-center">
			<u-avatar :src="info.icon" :size="70"></u-avatar>
			<view class="ml10">
				<h3>{{info.name!=undefined?info.name:''}}</h3>
				<view class="time">
					{{info.createTime!=undefined?info.createTime:''}}
				</view>
			</view>
		</view>
		<view class="cont mb10">
			<view class="">
				{{info.title!=undefined?info.title:''}}
			</view>
		</view>
		<view class="conts box imagess" v-if="info.conts.length!=0">
			<!-- <view class="mr5 mb5" v-for="(item,index) in info.conts"
			 :key="index">
				<u-image width="70px" height="70px" :src="item.url" border-radius="10" v-if="item.fileSuffix!='mp4'"></u-image>
				<u-image width="70px" height="70px" :src="item.firstFrame" border-radius="10" v-else></u-image>
			</view>
			 -->
			<view class="mr10 item" v-for="(ite,i) in info.conts" :key="i" @click="previewImage(info.conts,i)">
				<u-image :src="ite.fileSuffix=='mp4'?ite.firstFrame:ite.url" :fade="false" width="70px" height="70px">
					<!-- <u-loading slot="loading"></u-loading> -->
					<view class="" slot="error">
						<u-image width="70px" height="70px"
							src="https://yhykt.oss-cn-beijing.aliyuncs.com/946397E7649C436EA612AEC0DCDE3C858a9e3a8f3094a247e03cd930aa6fc67.png?Expires=4804127217&OSSAccessKeyId=LTAI4Fgsq7J3XQi7e2SRfzjJ&Signature=kX3E0QpqF6TdhmAHUKKkF9Sf%2BG8%3D">
						</u-image>
					</view>
				</u-image>
				<u-image src="@/static/home/icon_play.png" width="40rpx" height="40rpx" class="posa"
					v-if="ite.fileSuffix =='mp4'">
					<u-loading slot="loading"></u-loading>
				</u-image>
			</view>
		</view>
		<view class="chat box box-pack-end box-align-center mt10">
			<u-icon name="heart-fill" color="red"></u-icon>{{info.dzUsers!=undefined?info.dzUsers.length:0}}
			<u-icon name="chat" class="ml10"></u-icon>{{info.plNum!=undefined?info.plNum:0}}
		</view>
		<!-- <view class="chat-list">
			<u-icon name="heart"></u-icon>
			{{}}
		</view> -->
		<view class="chat-list source box box-pack-start box-align-center" v-if="info.dzUsers.length>0">
			<u-icon name="heart-fill" color="red"></u-icon>
			<view class="source-text box box-pack-start box-align-center">
				<view class="" v-for="(i,indexs) in info.dzUsers" :key="indexs">
					<span style="margin-left: 3px;" v-if="i.name!=undefined"> {{i.name}}</span>
				</view>
			</view>
		</view>
		<view class="btn" style="margin-top: 100px;">
			<u-button :ripple="true" ripple-bg-color="#626bf1" :customStyle="style" shape="circle" @click="goIndex">
				进入查看更多动态</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				style: {
					backgroundColor: "#626bf1",
					color: "#fff"
				},
				info: {
					name: '',
					createTime: '',
					icon: '',
					title: '',
					conts: [],
					dzUsers: []

				},
				form:uni.getStorageSync('accont'),
			}
		},
		onReady: () => {
			// this.setTitle()
			uni.setNavigationBarColor({
				frontColor: '#ffffff',
				backgroundColor: '#626bf1'
			})

		},
		onLoad(options) {
			//console.log('>>>>>>>>>>>>>>>>>>>>>>>');
			this.$nextTick(res => {
				// //console.log(options.data);
				//console.log(JSON.parse(decodeURIComponent(options.data)));
				// let a = JSON.parse(decodeURIComponent(options.data));
				this.info = JSON.parse(decodeURIComponent(options.data));
				// this.getData()
			})

			// this.getData()
		},
		methods: {
			goIndex() {
				//登录成功后，存储账号密码
				//console.log(uni.getStorageSync('accont'));
				//console.log(this.form);
				if (this.form) {
					this.$api.post({
						url: '/sysuser/login'
					}, this.form).then(res => {
						if (res.code == "0") {

							switch (res.result) {
								case 'password_error':
									this.$refs.uToast.show({
										title: '密码错误',
										type: 'warning',
									});
									break;
								case 'none':
									this.$refs.uToast.show({
										title: '无此用户，请先注册',
										type: 'warning',
									});
									break;
								case 'overtime':
									this.$refs.uToast.show({
										title: '服务到期，请联系学校管理员',
										type: 'warning',
									});
									break;
								default:
									uni.setStorageSync("user", res.user);
									uni.setStorageSync("roles", res.roles);
									//console.log(res.roles)
									uni.setStorageSync('role', res.roles[0]);
									//console.log(">>>>>unionid    " + this.unionid)
									//console.log(res.user)
									if (res.user.unionid == '') {
										this.updateUser(res.user.id, res.roles); //更新用户unionid信息
									} else {
										this.tohome(res.roles);
									}
									break;
							}
						}
					})
				} else {
					uni.reLaunch({
						url: '/pages/index/index'
					})
				}

			},
			updateUser(userid, roles) {
				this.$api.post({
					url: '/sysuser/modifyUnionid'
				}, {
					id: userid,
					appletsOpenid: this.openid,
					unionId: this.unionid
				}).then(s => {
					// //console.log(">>update user unionid success");
					this.tohome(roles);
				})
			},
			tohome(roles) {
				if (roles.length == 1) {
					if (roles[0] == 'tr') {
						uni.reLaunch({
							url: '/pages/home/home'
						})
					} else if (roles[0] == 'stu') {
						uni.reLaunch({
							url: '/pageHome/stuhome/home'
						})
					} else if (roles[0] == 'team') {
						uni.reLaunch({
							url: '/team/kc/changeSchool'
						})
					} else if (roles[0] == 'admin') {
						let ur = uni.getStorageSync("user");
						this.$api.post({
							url: '/yschool/getById'
						}, {
							id: ur.schoolId
						}).then(res => {
							uni.setStorageSync("currSchool", res.school)
							uni.reLaunch({
								url: '/team/schoolHome'
							})
						})
					}
				} else if (roles.length > 1) {
					uni.reLaunch({
						url: '/pages/index/selectRole'
					})
				}
			},
			previewImage(val, i) {
				if (val[i].fileSuffix == `mp4`) {
					uni.navigateTo({
						url: `/pageHome/video?url=` + val[i].url
					})
				} else {
					let it = JSON.stringify(val)
					uni.setStorage({
						key: 'item',
						data: it
					})
					// uni.setStorageSync("stu_preview",it);
					uni.navigateTo({
						url: `/pageHome/bjqShow?index=` + i + `&val=` + encodeURIComponent(it)
					})
				}
			},
			close() {
				this.setShow = false
			},
			getData(id) {
				//console.log("=========================");
				//是否有未读消息
				// let opts = {
				// 	url: '/ysjlist/bjqinfo',
				// 	method: 'post'
				// };
				// let param = {
				// 	bjqid: id
				// };
				// this.$api.httpRequest(opts, param).then(res => {
				// 		//console.log(res)
				// })
				this.$api.post({
					url: '/ysjlist/bjqinfo'
				}, {
					bjqid: id
				}).then(res => {
					//console.log(res)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		width: 100%;
		height: 100%;
		background-color: #fff;
		padding: 10px;

		.top {
			// padding: 10px 50px;
		}

		.time {
			font-size: 20rpx;
			color: #ccc;
		}

		.cont,
		.conts,
		.chat-list {
			padding-left: 45px;
		}

		.chat {
			padding-right: 15px;
		}

		.conts {
			flex-wrap: wrap;
		}

		.chat-list {
			background-color: #f5f5f5;
			border-radius: 5px;
			padding: 5px;
			margin-left: 45px;
		}

		.imagess {
			flex-wrap: wrap;

			.item {
				position: relative;
				margin-bottom: 20rpx;

				.posa {
					position: absolute;
					top: 50%;
					left: 50%;
					transform: translate(-50%, -50%);
				}
			}
		}

		.source {
			display: flex;
			background-color: #e8e8e869;
		}

		.source-text {
			margin-left: 16upx;
		}
	}
</style>
